|
STEP 4: Adding the Radio Button Sounds
|
Now, to add the radio button sounds. Unlike checkboxes, radio buttons cannot be checked and unchecked by repeatedly clicking on them. So, in our sonification we will make clicking on a radio button produce only one possible sound. We should choose a Groovoid that sounds "sharp" and "delicate" - something that is in keeping with the small point-like nature of a radio button. The Groovoid should still sound reasonably decisive, like the checkbox check sound we used in the previous step. Enter, UI-Click2.
Try fooling around with the radio buttons in the form below. They are now sonified, in addition to the checkboxes which are already sonified from the previous step. As you interact with the form, alternate between clicking on radio buttons and checkboxes to get a feel for the different sonification effects and how they contrast with each other yet also compliment each other.
Now, let's take a look at the HTML for this step. All the code that has been added since the previous step has been highlighted in red. Pay particular attention to the functions and event handlers that have been added.
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT LANGUAGE=JavaScript><!-- //
formSounds = new Music ();
function checkboxSound (checboxID) {
if (checboxID.checked) {
formSounds.play ('UI-Click7');
} else {
formSounds.play ('UI-Click6');
}
}
function radioButtonSound () {
formSounds.play ('UI-Click2');
}
// --></SCRIPT>
<FORM NAME="productForm" METHOD=GET ACTION="thanks.html">
<CENTER>
<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=4>
<TR>
<TD ALIGN=CENTER BGCOLOR=003366>
<FONT FACE="ARIAL,HELVETICA,VERDANA">
<FONT COLOR=00CCFF SIZE=6>
Blue Bass & the Neurotic Fishes<BR>
</FONT>
<FONT COLOR=FFFFFF SIZE=5>
-- Merchandise --
</FONT>
</FONT>
</TD>
</TR>
<TR>
<TD BGCOLOR=666699>
<FONT FACE="ARIAL,HELVETICA,VERDANA">
<CENTER><FONT SIZE=5>1. Select your poison...</FONT></CENTER>
<P>
<INPUT TYPE=checkbox NAME=tshirt ONCLICK="checkboxSound (this)">
<B>T-shirt ($15.95)</B>
<P>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT>Color</TD>
<TD>
<SELECT NAME=tshirtColor>
<OPTION>Oil Slick Black
<OPTION>Spiritual White
<OPTION SELECTED>Blood Clot Red
<OPTION>Summer Sky Blue
<OPTION>Underwater Aqua
<OPTION>Radioactive Green
<OPTION>Militia Khaki
<OPTION>Neon Pink
</SELECT>
</TD>
</TR>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT>Size</TD>
<TD>
<INPUT
TYPE=radio
NAME=tshirtSize
ONCLICK="radioButtonSound ()"
>
Small
<INPUT
TYPE=radio
NAME=tshirtSize
ONCLICK="radioButtonSound ()"
CHECKED
>
Medium
<INPUT
TYPE=radio
NAME=tshirtSize
ONCLICK="radioButtonSound ()"
>
Large
<INPUT
TYPE=radio
NAME=tshirtSize
ONCLICK="radioButtonSound ()"
>
X-Large
<INPUT
TYPE=radio
NAME=tshirtSize
ONCLICK="radioButtonSound ()"
>
XX-Large
</TD>
</TR>
</TABLE>
<HR SIZE=1 NOSHADE>
<INPUT TYPE=checkbox NAME=mug ONCLICK="checkboxSound (this)">
<B>Commemorative Reunion Mug ($19.95)</B>
- with printed mugshot of a band member of your choice
<P>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT>Band Member</TD>
<TD>
<SELECT NAME=mugPicture>
<OPTION SELECTED>Blue Bass (lead vocals & bass guitar)
<OPTION>Alec Littlefish (lead guitar & vocals)
<OPTION>Joe "The Octopus" Malone (drums & percussion)
<OPTION>Humphrey Proudfin (keyboards & vocals)
<OPTION>Gill Stronglung (harmony vocals)
<OPTION>Neville "The Blowfish" Ohrensborg (sax & horns)
</SELECT>
</TD>
</TR>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT>Mug Size</TD>
<TD>
<SELECT NAME=mugSize>
<OPTION>Diet Size (9 Fl.Oz.)
<OPTION SELECTED>Average Stomach (12 Fl.Oz)
<OPTION>Big Mama (20 Fl.Oz)
</SELECT>
</TD>
</TR>
</TABLE>
<HR SIZE=1 NOSHADE>
<B>Albums ($15.95 each)</B>
<P>
<INPUT TYPE=checkbox NAME=album1989 ONCLICK="checkboxSound (this)">
Underwater Blues (released 1989)<BR>
<INPUT TYPE=checkbox NAME=album1991 ONCLICK="checkboxSound (this)">
The Suffocating Sky (released 1991)<BR>
<INPUT TYPE=checkbox NAME=album1992 ONCLICK="checkboxSound (this)">
Suckerfish Rising (released 1992)<BR>
<INPUT TYPE=checkbox NAME=album1994 ONCLICK="checkboxSound (this)">
Psychedelic Abyss (released 1994)<BR>
<INPUT TYPE=checkbox NAME=album1997 ONCLICK="checkboxSound (this)">
The Little Fish That Could (released 1997)<BR>
<INPUT TYPE=checkbox NAME=album1998 ONCLICK="checkboxSound (this)">
Have You Eaten Fish Today (new release)<BR>
<HR SIZE=1 NOSHADE>
</FONT>
</TD>
</TR>
<TR>
<TD BGCOLOR=9999CC>
<FONT FACE="ARIAL,HELVETICA,VERDANA">
<CENTER><FONT SIZE=5>2. Pay for the poison...</FONT></CENTER>
<P>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT>Type of Credit Card</TD>
<TD>
<INPUT
TYPE=radio
NAME=creditCardType
ONCLICK="radioButtonSound ()"
>
American Express
<INPUT
TYPE=radio
NAME=creditCardType
ONCLICK="radioButtonSound ()"
CHECKED
>
VISA
<INPUT
TYPE=radio
NAME=creditCardType
ONCLICK="radioButtonSound ()"
>
Mastercard
</TD>
</TR>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT><B>*Name on Credit Card</B></TD>
<TD><INPUT TYPE=text SIZE=30 NAME=creditCardName></TD>
</TR>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT><B>*Credit Card Number</B></TD>
<TD><INPUT TYPE=text SIZE=30 NAME=creditCardNumber></TD>
</TR>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT>Expiration Date</TD>
<TD>
<SELECT NAME=creditCardExpirationYear>
<OPTION SELECTED>1998
<OPTION>1999
<OPTION>2000
<OPTION>2001
<OPTION>2002
<OPTION>2003
<OPTION>2004
</SELECT>
<SELECT NAME=creditCardExpirationMonth>
<OPTION SELECTED>01 Jan
<OPTION>02 Feb
<OPTION>03 Mar
<OPTION>04 Apr
<OPTION>05 May
<OPTION>06 Jun
<OPTION>07 Jul
<OPTION>08 Aug
<OPTION>09 Sep
<OPTION>10 Oct
<OPTION>11 Nov
<OPTION>12 Dec
</SELECT>
</TD>
</TR>
</TABLE>
<HR SIZE=1 NOSHADE>
</FONT>
</TD>
</TR>
<TR>
<TD BGCOLOR=CCCCFF>
<FONT FACE="ARIAL,HELVETICA,VERDANA">
<CENTER><FONT SIZE=5>3. Deliver the poison...</FONT></CENTER>
<P>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT>Shipping & Handling Option</TD>
<TD>
<SELECT NAME=shippingOption>
<OPTION>US Mail (7 day delivery)
<OPTION SELECTED>UPS (2 day delivery)
<OPTION>Fedex (overnight delivery)
</SELECT>
</TD>
</TR>
<TR>
<TD COLSPAN=2 ALIGN=CENTER> </TD>
</TR>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT><B>*Name</B></TD>
<TD><INPUT TYPE=TEXT NAME=shippingAddressName SIZE=40></TD>
</TR>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT><B>*Address Line 1</B></TD>
<TD><INPUT TYPE=TEXT NAME=shippingAddressLine1 SIZE=40></TD>
</TR>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT>Address Line 2</TD>
<TD><INPUT TYPE=TEXT NAME=shippingAddressLine2 SIZE=40></TD>
</TR>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT><B>*City</B></TD>
<TD><INPUT TYPE=TEXT NAME=shippingAddressCity SIZE=40></TD>
</TR>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT><B>*State</B> (or Province, or Region)</TD>
<TD><INPUT TYPE=TEXT NAME=shippingAddressState SIZE=40></TD>
</TR>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT><B>*Zip Code</B> (or Postal Code)</FONT></TD>
<TD><INPUT TYPE=TEXT NAME=shippingAddressZip SIZE=40></TD>
</TR>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT><B>*Country</B></TD>
<TD><INPUT TYPE=TEXT NAME=shippingAddressCountry SIZE=40 VALUE="USA"></TD>
</TR>
</TABLE>
<HR SIZE=1 NOSHADE>
</FONT>
</TD>
</TR>
<TR>
<TD BGCOLOR=000000>
<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR>
<TD ALIGN=LEFT><INPUT TYPE=reset VALUE="Reset and start over"></TD>
<TD ALIGN=RIGHT><INPUT TYPE=submit VALUE="BUY the poison NOW!!!"></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<P>
</CENTER>
</FORM>
<SCRIPT LANGUAGE=JavaScript><!-- //
formSounds.stubEmbed ('stub.rmf');
// --></SCRIPT>
|
Just like the previous step, where we sonified checkboxes by adding the checkboxSound function, we have now added the new radioButtonSound function for sonifying our form's radio buttons. However, unlike the checkboxSound function, the radioButtonSound function is extremely simple. All it does is play a Groovoid through the "formSounds" Music Object instance. In fact, we could just as easily have placed the code that is inside the radioButtonSound function inside each of the radio button's ONCLICK event handlers and then dispensed with the additional function entirely. So, why define a custom function?
Well, it is common wisdom in the field of programming to move repeated code segments into separate function definitions and then simply call that function in all the places where you would have repeated the same code segment. This makes it really easy to make one simple change in a single function and have that change be shared by all the places where that function is called. To use our own example, if we wanted to easily experiment with Groovoids to choose just the right sound for the radio buttons, we could very easily try different Groovoids in the radioButtonSound function, each time reloading the page after we had modified the function.
Using this separate function approach also allows us to build a more complex sonification behavior for radio buttons if we care to, much like the checkboxSound function. In this event, sharing a sonification behavior that's implemented in a custom function not only becomes a big timesaver, but also represents a greater efficiency in code size.